package com.snake.mylibrary.utils;

import android.os.HandlerThread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 线程池管理工具封装线程了２个线程池,和一个单独的带消息循环的子线程
 */

public class ThreadManagerUtil {

    private static ThreadManagerUtil sInstance = new ThreadManagerUtil();
    private ExecutorService mSingleThreadExecutor;
    private ExecutorService mFixedThreadPool;
    private HandlerThread mHandlerThread;

    private ThreadManagerUtil(){
        init();
    }

    private void init() {
        mSingleThreadExecutor = Executors.newSingleThreadExecutor();
        mFixedThreadPool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()*2+1);
        mHandlerThread = new HandlerThread("work-handler-1");
        mHandlerThread.start();
    }

    public static ThreadManagerUtil getInstance() {
        return sInstance;
    }

    public ExecutorService getFixedThreadPool() {
        return mFixedThreadPool;
    }

    public ExecutorService getSingleThreadExecutor() {
        return mSingleThreadExecutor;
    }

    public HandlerThread getHandlerThread() {
        return mHandlerThread;
    }
}
